<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>收款</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css" />
		<link rel="stylesheet" href="../css/pravate/cash.css" />
		<script type="text/javascript" src="../js/template-web.js"></script>
		<script type="text/javascript" src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/jquery-2.1.0.js"></script>
		<script type="text/javascript" src="../js/config.js"></script>
		<script type="text/javascript" src="../js/mobile-detect.min.js"></script>
		<script type="text/javascript" src="../controll/index.js"></script>
		<script type="text/javascript" src="../js/common.js"></script>
		<script type="text/javascript" src="../controll/cash.js"></script>
	</head>

	<body>
		<div style="min-height: 100%;">
			<div class="header">
				<div class="nav">
					<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="padding-left: 10px;"></a>
					<div class="nav-wraper">
						<div class="mui-col-sm-6 nav-wraper-item active">普通收款</div>
						<div class="mui-col-sm-6 nav-wraper-item depositAct">预授权</div>
					</div>
				</div>
				<p class="useInfo opa-hidden">
					<a href="instructions.html" style="color: white;" class="use_word">
						<img src="../img/ic_deposit_explain@2x.png" />使用说明
					</a>
					<span style="opacity: 0.5;float: right;">预收款(冻结):￥<i class="price-top">0</i></span>
				</p>
				<div class="price">
					<span>￥</span>
					<input oninput="if(value.length>10)value=value.slice(0,10)" class="price-cash" type="number" autofocus="autofocus" placeholder="0.00" />
				</div>
			</div>
			<div class="remarks">
				<span>备注信息：</span>
				<input class="pay_remarks" type="text" placeholder="请输入备注信息(选填)" />
			</div>

			<ul class="mui-table-view funList" style="margin: 15px 0;">
				<li class="mui-table-view-cell" data-url="public/scanning.html" data-id="scanning.html">
					<a class="mui-navigate-right">
						<img src="../img/ic_receivables_scan@2x.png" />
						<span>扫一扫订单查询</span>
					</a>
				</li>
			</ul>
			<div class="cashSk">
				<ul class="mui-table-view funList">
					<li class="mui-table-view-cell" data-url="zhang.html" data-id="zhang">
						<a class="mui-navigate-right">
							<img src="../img/ic_receivables_list@2x.png" />
							<span>收款列表</span>
						</a>
					</li>
					<li class="mui-table-view-cell" data-url="my/zhangben/se1.html" data-id="se1.html">
						<a class="mui-navigate-right">
							<img src="../img/ic_receivables_search@2x.png" />
							<span>收款查询</span>
						</a>
					</li>
				</ul>
				<div class="footer">
					<script type="text/template" id="diposit0">
						{{if status=='p1'}}
						<button type="button" class="mui-btn backCardPay" style="margin-right: 5%;"><img src="../img/ic_deposit_unionpay@2x.png"/>银行卡收款</button>
						<button type="button" class="mui-btn pay_scan"><img src="../img/ic_deposit_scan_white@2x.png" />扫码收款</button> {{else}}
						<button type="button" class="mui-btn pay_scan" style="width: 100%;"><img src="../img/ic_deposit_scan_white@2x.png" style="top: 9px;" />扫码收款</button> {{/if}}
					</script>
				</div>
			</div>
			<!--押金收款-->
			<div class="deposit mui-hidden">
				<div>
					<ul class="mui-table-view funList">
						<li class="mui-table-view-cell" data-url="loadList.html" data-id="loadList.html">
							<a class="mui-navigate-right">
								<img src="../img/ic_deposit_settlement@2x.png" />
								<span>全部订单</span>
							</a>
						</li>
					</ul>
					<ul class="mui-table-view funList" style="margin-top: 15px;">
						<li class="mui-table-view-cell" data-url="loadFunc.html" data-id="loadFunc.html">
							<a class="mui-navigate-right">
								<img src="../img/ic_receivables_search@2x.png" />
								<span>预授权账单查询</span>
							</a>
						</li>
					</ul>
				</div>
				<div class="footer">
					<script type="text/template" id="diposit">
						{{if status=='p1'}}
						<button type="button" class="mui-btn warning backCard backCardPay deposit_x" style="margin-right: 5%;">
								<img src="../img/ic_deposit_unionpay@2x.png"/>银行卡预授权
							</button>
						<button type="button" class="mui-btn warning pay_deposit">
								<img src="../img/ic_deposit_scan_white@2x.png"/>扫码预授权
							</button> {{else}}
						<button type="button" class="mui-btn warning pay_deposit" style="width: 100%;">
								<img src="../img/ic_deposit_scan_white@2x.png" style="top: 9px;" />扫码预授权
							</button> {{/if}}
					</script>
				</div>
			</div>
		</div>
		<script>
			mui.init();
			mui.plusReady(function() {
				var temData = {
					status: "v1"
				};
				if(getSysInfo().search("P1")!= -1) {
					temData = {
						status: "p1"
					};
				}
				var str1 = template("diposit", temData);
				$(".footer").eq(1).append(str1);
				var str2 = template("diposit0", temData);
				$(".footer").eq(0).append(str2);
				//普通收款
				mui("body").on("tap", ".pay_scan", function(e) {
					$("input").blur();
					if(regularCheck() == false) {
						return false;
					}
					mui.openWindow({
						url: "../view/public/barcode_scan.html",
						id: "barcode_scan.html",
						extras: {
							price: Number($(".price-cash").val()),
							remark: $(".pay_remarks").val() ? $(".pay_remarks").val() : ""
						}
					});
				})
				//预授权收款
				mui("body").on("tap", ".pay_deposit", function(e) {
					$("input").blur();
					if(regularCheck() == false) {
						return false;
					}
					var datas = {
						token: localStorage.getItem("token"),
						remarks: $(".pay_remarks").val() ? $(".pay_remarks").val() : "",
						price: Number($(".price-cash").val()),
					}
					mui.openWindow({
						url: "../view/public/barcode_scan1.html",
						id: "barcode_scan1.html",
						extras: {
							datas: datas
						}
					});
				})
				//点击li标签实现跳转
				mui("body").on("tap", ".mui-table-view-cell", function() {
					var that = $(this);
					mui.openWindow({
						url: that.attr("data-url"),
						id: that.attr("data-id"),
						extras: {
							pay_status: 1,
							url_sign: "home"
						}
					});
				})
				//点击银行卡收款/预授权
				var backSign = true;
				var backTime = 3;
				mui("body").on("tap", ".backCardPay", function() {
					$("input").blur();
					var that = $(this);
					if((regularCheck() == false) || (backSign == false)) {
						return false;
					}
					var setInt = setInterval(function() {
						if(backTime <= 0) {
							clearInterval(setInt);
							backTime = 3;
							backSign = true;
							return false;
						}
						backSign = false;
						backTime--;
					}, 1000);
					plus.nativeUI.showWaiting("正在处理中...");
					if(that.hasClass("deposit_x")) { //如果是预授权银行卡收款
						require(weburl + BankOrderCreate, "json", "post", {
							token: localStorage.getItem("token"),
							amount: $(".price-cash").val(),
							pay_type: "auth"
						}, function(response) {
							plus.nativeUI.closeWaiting();
							if(response.status == "success") {
								var main = plus.android.runtimeMainActivity();
								var data = {
									token: localStorage.getItem("token"),
									amount: response.data[0].amount,
									barcodeType: 0,
									orderInfo: $(".pay_remarks").val() ? $(".pay_remarks").val() : "",
									orderNoSFT: response.data[0].out_trade_no,
									payCallUrl: weburl + "/api/"
								}
								main.BankCarTrade("3", JSON.stringify(data));
								return false;
							}
							mui.alert(response.msg, " ", "关闭", function() {}, "div");
						}, function(xhr) {
							plus.nativeUI.closeWaiting();
							mui.alert("创建订单失败，请稍后重试！", " ", "关闭", function() {}, "div");
						})
						return false;
					}
					//如果是普通收款
					require(weburl + BankOrderCreate, "json", "post", {
						token: localStorage.getItem("token"),
						amount: $(".price-cash").val(),
						pay_type: "pay"
					}, function(response) {
						console.log(JSON.stringify(response));
						plus.nativeUI.closeWaiting();
						if(response.status == "success") {
							var main = plus.android.runtimeMainActivity();
							var data = {
								token: localStorage.getItem("token"),
								amount: response.data[0].amount,
								barcodeType: 0,
								orderInfo: $(".pay_remarks").val() ? $(".pay_remarks").val() : "",
								orderNoSFT: response.data[0].out_trade_no,
								payCallUrl: weburl + "/api/"
							}
							main.BankCarTrade("1", JSON.stringify(data));
							return false;
						}
						mui.alert(response.msg, " ", "关闭", function() {}, "div");
					}, function(xhr) {
						plus.nativeUI.closeWaiting();
						mui.alert("创建订单失败，请稍后重试！", " ", "关闭", function() {}, "div");
					})
				})

				function regularCheck() {
					var remarks = $(".pay_remarks").val();
					var price = $(".price-cash").val();
					var index = $(".active").index();
					var exp = /^[0-9]+(.[0-9]{1,2})?$/;
					if(!exp.test(price)) {
						mui.alert("收款金额不合法", " ", "关闭", function() {}, "div");
						return false;
					}
					//如果金额为0
					if(!(price * 1 > 0)) {
						mui.alert("收款金额不能为0", " ", "关闭", function() {}, "div");
						return false;
					}
					if(remarks == "") {
						if(index != 0) {
							mui.alert("备注信息不能为空", " ", "关闭", function() {}, "div");
							return false;
						}
					}
				}
				mui("body").on("tap", ".use_word", function() {
					mui.openWindow("instructions.html", "instructions.html");
				})
			})
		</script>
	</body>

</html>